package com.app.dao.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.app.dao.UserDao;
import com.app.entity.User;

@Repository
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {
	private final Logger logger = LoggerFactory.getLogger(getClass());
	
	@SuppressWarnings("unchecked")
	public User findUserByParameter(User user) {
		List<User> list = getHibernateTemplate().find("from User where name = '" + user.getName() + "' and password = '" + user.getPassword() + "'");
		
		if(list != null && list.size()>0){
			logger.debug("查找用户成功");
			return list.get(0);
		}
		
		logger.debug("查找用户失败");
		return user;
	}

	public void updatePassword(User user) {
		getHibernateTemplate().update(user);
	}

}
